package com.wzw.weibo;

import gui.ava.html.image.generator.HtmlImageGenerator;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

public class UtilTools {
	public static boolean saveScreen(){
		  try {
		   //获取屏幕
		   Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		   BufferedImage bim = new Robot()
		     .createScreenCapture(new Rectangle(0, 0, dim.width,
		       dim.height));
		   ImageIO.write(bim, "jpg", new File("C:\\test.jpg"));
		  } catch (Exception e) {
			  e.printStackTrace();
			  return false;
		  }
		  return true;
		}
		
		public static boolean saveHTML(String htmlString, String imgRealPathName, String imgHtmlRealPathName){
			HtmlImageGenerator imageGenerator = new HtmlImageGenerator(); 
			//imageGenerator.loadHtml("<b>Hello World!</b> Please goto <a title=\"Goto Google\" href=\"http://www.google.com\">Google</a>."); 
			imageGenerator.loadHtml(htmlString);
			//imageGenerator.loadUrl("http://localhost:8080/xztz/pge-1.html");
			imageGenerator.saveAsImage(imgRealPathName); 
			if(imgHtmlRealPathName!=null)
				imageGenerator.saveAsHtmlWithMap(imgHtmlRealPathName, imgRealPathName);
			return true;
		}
		
		public static String generateHTML(String imgUrl, String name, String toast){
			StringBuilder sb = new StringBuilder();
			sb.append("<div style=\"width:692px; height:386px; background-image:'" + imgUrl + "'\">");
			sb.append("	<div style=\"width:350px;height:150px;  margin-top:175px; margin-left:46px; font-size:20px; color:#FFFFFF; line-height:30px;\">");
			sb.append("值此佳节，<br>您的朋友 " + name + " 祝您：<br>" + toast);
			sb.append("	</div>");
			sb.append("</div>");
			return sb.toString();
		}
		
//		public static void compressPic(){
//			PicCompress picCompress = new PicCompress();
//			picCompress.doThumbCompress(path, myFile.getFileName(),true);
//			picCompress.setHEIGHT(85);
//			picCompress.doThumbCompress(path+"tn/",myFile.getFileName(),false);
//		}
		
		public static void main(String[] args){
			saveScreen();
		}
}
